﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace LibrarySystem
{
    public partial class Admin : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                liBook1.Enabled = true;
                liBook2.Enabled = true;
                liBook3.Enabled = true;
                liAuthor1.Enabled = false;
                liBorrower1.Enabled = false;
                searchBox.Attributes["placeholder"] = "Sök efter bok...";
            }
            

            if (Session["Username"] != null)
            {
                if (Session["Admin"].ToString() == "0")
                {
                    adminDiv.Visible = false;
                    Response.Redirect("homePage.aspx");
                }
                else if (Session["Admin"].ToString() == "1")
                {
                    adminDiv.Visible = true;
                }
            }
            else { Response.Redirect("homePage.aspx"); }
        }

        protected void logoutBtn_Click(object sender, EventArgs e)
        {
            Session.RemoveAll();
            Response.Redirect("homePage.aspx");
        }

        protected void searchBtn_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("adminSearch.aspx?val=" + searchDropDown.SelectedValue + "&term=" + Server.UrlEncode(searchBox.Text));
        }


        protected void adminBookBtn_Click(object sender, EventArgs e)
        {
            liBook1.Enabled = true;
            liBook2.Enabled = true;
            liBook3.Enabled = true;
            liAuthor1.Enabled = false;
            liBorrower1.Enabled = false;
            searchBox.Attributes["placeholder"] = "Sök efter bok...";
        }

        protected void adminAuthorBtn_Click(object sender, EventArgs e)
        {
            liBook1.Enabled = false;
            liBook2.Enabled = false;
            liBook3.Enabled = false;
            liAuthor1.Enabled = true;
            liBorrower1.Enabled = false;
            searchBox.Attributes["placeholder"] = "Sök efter författare...";
        }

        protected void adminBorrowerBtn_Click(object sender, EventArgs e)
        {
            liBook1.Enabled = false;
            liBook2.Enabled = false;
            liBook3.Enabled = false;
            liAuthor1.Enabled = false;
            liBorrower1.Enabled = true;
            searchBox.Attributes["placeholder"] = "Sök efter användare...";
        }


        protected void adminAddBook_Click(object sender, EventArgs e)
        {
            Response.Redirect("adminAddBook.aspx");
        }
        protected void adminAddAuthor_Click(object sender, EventArgs e)
        {
            Response.Redirect("adminAddAuthor.aspx");
        }
        protected void adminAddUser_Click(object sender, EventArgs e)
        {
            Response.Redirect("adminAddUser.aspx");
        }

        
    }
}